<template>
  <div id="main">
    <el-container>
      <el-header class="main-header">
        <a href="http://www.bestproperty.com.mm" target="_blank">
        <span style='color:#f60; display: inline-block'>
          <img class="logo-header" src="static/logoh.png" alt="">BestProperty<!--<font class="balck">Developer</font>-->
        </span>
        </a>
        <!--<el-dropdown class="el-menu-demo">-->
        <!--<span class="el-dropdown-link">{{$t('m.Select')}}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
        <!--</span>-->
        <!--<el-dropdown-menu slot="dropdown">-->
        <!--<el-dropdown-item @click.native="signOut" style="min-width: 100px;text-align: center;">{{$t('m.Logout')}}</el-dropdown-item>-->
        <!--</el-dropdown-menu>-->
        <!--</el-dropdown>-->
        <!--<span class="changeLang" @click="changeLang">{{lang}}</span>-->
        <!--<span class="userName">{{this.$store.state.userName || username}}</span>-->
      </el-header>
      <el-container class="sidebar nav-bar">
        <el-aside class="container" width="260px">
          <el-row>
            <el-col :span="24">
              <el-menu
                class="el-menu-vertical-demo"
                background-color="#FAFAFA"
                text-color="#999"
                active-text-color="#000"
                :unique-opened="false"
                :default-active="activeIndex"
              >
                <!--不要下拉的导航-->
                <el-menu-item index="1" @click="$router.push('/restaurants')">
                  <i class="el-icon-setting"></i>
                  <span slot="title">Restaurants</span>
                </el-menu-item>

                <el-menu-item index="2" @click="$router.push('/activityList')">
                  <i class="el-icon-menu"></i>
                  <span slot="title">Activity</span>
                </el-menu-item>

                <el-menu-item index="3" @click="$router.push('/discount')">
                  <i class="el-icon-upload"></i>
                  <span slot="title">Discount</span>
                </el-menu-item>

                <el-menu-item index="4" @click="$router.push('/blockBooking')">
                  <i class="el-icon-mobile-phone"></i>
                  <span slot="title">Block booking</span>
                </el-menu-item>

                <el-menu-item index="5" @click="$router.push('/bookingList')">
                  <i class="el-icon-tickets"></i>
                  <span slot="title">Booking</span>
                </el-menu-item>

                <el-menu-item index="6" @click="$router.push('/')">
                  <i class="el-icon-goods"></i>
                  <span slot="title">Statistics</span>
                </el-menu-item>

                <el-menu-item index="7" @click="$router.push('/userList')">
                  <i class="el-icon-bell"></i>
                  <span slot="title">Restaurant app users</span>
                </el-menu-item>

                <el-menu-item index="8" @click="$router.push('/consumerList')">
                  <i class="el-icon-edit"></i>
                  <span slot="title">Consumers</span>
                </el-menu-item>

                <el-menu-item index="9" @click="$router.push('/schedule')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Schedule</span>
                </el-menu-item>

                <el-menu-item index="10" @click="$router.push('/busLineIndex')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Bus  Line Index</span>
                </el-menu-item>
                <el-menu-item index="10" @click="$router.push('/busStopMap')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Bus Stop Map</span>
                </el-menu-item>

                <el-menu-item index="11" @click="$router.push('/busRouterList')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Bus Route</span>
                </el-menu-item>

                <el-menu-item index="12" @click="$router.push('/busStopList')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Bus Stop</span>
                </el-menu-item>

                <el-menu-item index="13" @click="$router.push('/routeList')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Route List</span>
                </el-menu-item>
                <!--为了本地测试时页面跳转方便临时加的导航-->
                <el-menu-item index="14" @click="$router.push('/propertyIndex')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Property Index</span>
                </el-menu-item>
                <el-menu-item index="15" @click="$router.push('/categoryTranslationIndex')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Category Transition Index</span>
                </el-menu-item>
                <el-menu-item index="16" @click="$router.push('/shopUser')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Shop User</span>
                </el-menu-item>
                <el-menu-item index="17" @click="$router.push('/verificationIndex')">
                  <i class="el-icon-refresh"></i>
                  <span slot="title">Verification Index</span>
                </el-menu-item>
              </el-menu>
            </el-col>
          </el-row>
        </el-aside>
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import {signOutUser} from '@/api/mgc_api'

  export default {
    name: 'Main',
    data() {
      return {
        isCollapse: true,
        username: '',
        lang: 'English',
        activeIndex: '',
        routerArr: [{
          path: '/propertyList',
          activeIndex: '0'
        }, {
          path: '/buy',
          activeIndex: '1'
        }, {
          path: '/newDevelopment',
          activeIndex: '2'
        }, {
          path: '/rent',
          activeIndex: '3'
        }]
      }
    },
    methods: {
      // message alert
      messageT(type, msg) {
        this.$message({
          showClose: true,
          message: msg,
          duration: 1500,
          type: type
        })
      },
      // sign out
      signOut() {
        signOutUser({}).then((res) => {
          console.log(res)
          if (res.data) {
            var data = res.data
            if (data.errorID === 0 || data.errorID === 100004) {
              localStorage.removeItem('username')
              this.$store.commit('updateUserName', '')
              this.$store.commit('updateDeveloperId', '')
              this.$store.commit('updateAccount', '')

              // 尝试清除谷歌登录
              try {
                var auth2 = window.gapi.auth2.getAuthInstance()
                auth2.signOut()
              } catch (e) {

              }
              // 尝试清除facebook登录
              try {
                FB.logout(function (response) {
                  // Person is now logged out
                })
              } catch (e) {

              }

              this.$router.push('/login')
            } else {
              console.log(data.errorID)
              this.messageT('error', data.message)
            }
          }
        })
          .catch((error) => {
            console.log(error)
            this.messageT('error', 'error,please try again leter')
          })
      },
      initPage() {
        let username = localStorage.getItem('username')
        if (username) {
          this.username = username
        }
      },
      // 切换语言
      changeLang() {
        if (this.$i18n.locale == 'MM') {
          this.$i18n.locale = 'US'
          this.lang = 'ျမန္မာ'
          this.$store.commit('updateLang', 'US')
          localStorage.setItem('lang', 'US')

        } else if (this.$i18n.locale == 'US') {
          this.$i18n.locale = 'MM'
          this.lang = 'English'
          this.$store.commit('updateLang', 'MM')
          localStorage.setItem('lang', 'MM')
        }
      },
      getActiveRoute() {
        for (var i = 0; i < this.routerArr.length; i++) {
          if (this.routerArr[i].path == this.$route.path) {
            this.activeIndex = this.routerArr[i].activeIndex
          }
        }
      },
    },
    watch: {
      // 如果路由有变化，会再次执行
      "$route": "getActiveRoute"
    },
    mounted() {
      this.getActiveRoute()
      this.initPage()
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  /*.el-menu-vertical-demo:not(.el-menu--collapse) {*/
  /*width: 200px;*/
  /*min-height: 400px;*/
  /*}*/
  .main-header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: 60px;
    padding-right: 0;
    background: #fff;
    border-bottom: 1px solid #e6e6e6;
    z-index: 100;
  }

  .main-header span {
    color: rgba(0, 0, 0, 0.65);
    font-size: 20px;
    padding-left: 10px;
    float: left;
    line-height: 60px;
  }

  .el-menu-demo {
    float: right;
  }

  .main-header .el-submenu .el-menu-item {
    max-width: 120px;
    min-width: 100px;
    width: 100%;
  }

  .main-header .userName {
    float: right;
    font-size: 16px;
    padding-right: 25px;
  }

  .main-header .changeLang {
    float: right;
    font-size: 16px;
    padding-right: 25px;
    cursor: pointer;
    user-select: none;
  }

  .container {
    /*border-top: 2px solid rgb(40, 52, 70);*/
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    /*background: #324157;*/
    background: #FAFAFA;
    height: 100%;
  }

  .container .el-menu {
    border-right: 0;
  }

  .main {
    margin-left: 310px;
    overflow: auto;
    /*background: #fff;*/
    padding: 62px 0 20px 0;
  }

  .logo-header {
    width: 30px;
    height: 30px;
    vertical-align: middle;
    margin-right: 5px;
    margin-top: -5px;
  }

  .balck {
    /*color: #060606;*/
    margin-left: 8px;
  }

  .main-header span.el-dropdown-link {
    font-size: 14px;
    padding: 0 10px;
  }
</style>
<!--覆盖全局样式-->
<style>
  /*使disabled的input输入框的文字颜色变深一点*/
  .el-input.is-disabled .el-input__inner {
    color: #000 !important;
  }

  /*使disabled的textarea输入框的文字颜色变深一点*/
  .el-textarea.is-disabled .el-textarea__inner {
    color: #000 !important;
  }

  /*单选框的label*/
  .el-radio__input.is-disabled + span.el-radio__label {
    color: #000 !important;
  }

  /*单选框的圆*/
  .el-radio__input.is-disabled .el-radio__inner, .el-radio__input.is-disabled.is-checked .el-radio__inner {
    background-color: #fff;
    border-color: #000;
  }

  /*单选框圆里的点*/
  .el-radio__input.is-disabled.is-checked .el-radio__inner:after {
    background-color: #000 !important;
  }

  /*复选框前的正方形*/
  .el-checkbox__input.is-disabled .el-checkbox__inner {
  }

  /*复选框里的钩号*/
  .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #000 !important;
  }

  /*复选框的lable*/
  .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000 !important;
  }

  /*去掉下边框*/
  .search-box {
    border: solid 1px transparent !important;
  }

  /*定义奇数行的样式*/
  .el-table__row.odd-row {
    background: #fafafa;
  }

  /*定义偶数行的样式*/
  .el-table__row.even-row {
    background: #fff;
  }

  /*被选中的样式层级最高，设置选中后行的样式*/
  .el-table__row.current-row td {
    background: #FBE498 !important;
  }

  /*覆盖鼠标hover的样式*/
  .el-table--enable-row-hover .el-table__body tr:hover > td {
    background-color: #EBF2FE;
  }

</style>
